home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / unix / mp14tar.z / mp14tar / mpack / macndlog.c < prev    next >
C/C++ Source or Header  |  1994-06-01  |  7KB  |  264 lines

  1. /* macndlog.c -- dialog utilities for nifty application library
  2.  *
  3.  * (C) Copyright 1990-1994 by Christopher J. Newman
  4.  * All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of Christopher J. Newman not be used in
  11.  * advertising or publicity pertaining to distribution of the software without
  12.  * specific, written prior permission.  Christopher J. Newman makes no
  13.  * representations about the suitability of this software for any purpose.  It
  14.  * is provided "as is" without express or implied warranty.
  15.  *
  16.  * CHRISTOPHER J. NEWMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  17.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
  18.  * SHALL CHRISTOPHER J. NEWMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  19.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  20.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  21.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  22.  * OF THIS SOFTWARE.
  23.  *
  24.  * Author:    Christopher J. Newman
  25.  * Message:    This is a nifty program.
  26.  */
  27.  
  28. #include "macnapp.h"
  29. #ifndef THINK_C
  30. #include <ToolUtils.h>
  31. #endif
  32.  
  33. /* place to save modifiers from a modal dialog */
  34. static short dialog_modifiers;
  35.  
  36. /* a filter proc which handles Return, Enter, Esc, command-period properly
  37.  */
  38. pascal Boolean NAfilterProc(dialog, pevent, item)
  39.     DialogPtr        dialog;
  40.     EventRecord        *pevent;
  41.     short            *item;
  42. {
  43.     dialog_modifiers = pevent->modifiers;
  44.     if (pevent->what == autoKey || pevent->what == keyDown) {
  45.         switch (pevent->message & charCodeMask) {
  46.             case '\r':
  47.             case '\n':
  48.                 *item = 1;
  49.                 goto HILITE;
  50.             
  51.             case '.':
  52.                 if (!(pevent->modifiers & cmdKey)) break;
  53.             case '\033':
  54.                 *item = 2;
  55.             HILITE:
  56.                 NAflashButton(dialog, *item);
  57.                 return (true);
  58.         }
  59.     }
  60.     
  61.     return (false);
  62. }
  63.  
  64. /* send events from a modal dialog box to the control procedure.
  65.  * if no ctrlp in window structure, then a simple OK/CANCEL box is assumed.
  66.  * returns item number of last item event.
  67.  */
  68. short NAmodalLoop(winp)
  69.     na_win    *winp;
  70. {
  71.     short            item;
  72.     short            status = NA_NOTPROCESSED;
  73.     ControlHandle    ctrl;
  74.     Point            pt;
  75.     
  76.     * (long *) &pt = 0L;
  77.     do {
  78.         ModalDialog(NAfilterProc, &item);
  79.         if (winp->ctrlp == (na_ctrlp) NULL) {
  80.             if (item == iOk || item == iCancel)    break;
  81.         } else {
  82.             NAgetDHandle(winp->pwin, item, &ctrl);
  83.             status = (*winp->ctrlp)(winp, pt, item, dialog_modifiers, ctrl);
  84.         }
  85.     } while (status >= NA_NOTPROCESSED);
  86.     
  87.     return (item);
  88. }
  89.  
  90. /* enable/disable a control in a dialog window
  91.  */
  92. #ifdef __STDC__
  93. void NAenableDItem(DialogPtr dialog, short item, Boolean on)
  94. #else
  95. void NAenableDItem(dialog, item, on)
  96.     DialogPtr    dialog;
  97.     short        item;
  98.     Boolean        on;
  99. #endif
  100. {
  101.     short    type;
  102.     Handle            ctrl;
  103.     short            ty;
  104.     Rect            box;
  105.     
  106.     GetDItem(dialog, item, &ty, &ctrl, &box);
  107.     type = ty;
  108.     if (on) type &= ~itemDisable;
  109.     else    type |= itemDisable;
  110.     if (type == statText) type = editText;
  111.     if (type == editText | itemDisable) type = statText;
  112.     SetDItem(dialog, item, type, ctrl, &box);
  113. }
  114.  
  115. /* hilite a control in a dialog window
  116.  */
  117. #ifdef __STDC__
  118. void NAhiliteDItem(DialogPtr dialog, short item, short how)
  119. #else
  120. void NAhiliteDItem(dialog, item, how)
  121.     DialogPtr    dialog;
  122.     short        item;
  123.     short        how;
  124. #endif
  125. {
  126.     Handle        ctrl;
  127.     short        type;
  128.     Rect        box;
  129.     PenState    tmpPen;
  130.     
  131.     GetDItem(dialog, item, &type, &ctrl, &box);
  132.     if (type & ctrlItem) {
  133.         HiliteControl((ControlHandle) ctrl, how);
  134.     } else if (type & (statText | editText) && how == 255) {
  135.         GetPenState(&tmpPen);
  136.         PenNormal();
  137.         PenPat(QD(gray));
  138.         if (type & statText) {
  139.             PenMode(patBic);
  140.             PaintRect(&box);
  141.         } else {
  142.             InsetRect(&box, -3, -3);
  143.             FrameRect(&box);
  144.         }
  145.         SetPenState(&tmpPen);
  146.     }
  147. }
  148.  
  149. /* make an item visible/invisible in a dialog window
  150.  */
  151. #ifdef __STDC__
  152. void NAvisibleDItem(DialogPtr dialog, short item, Boolean show)
  153. #else
  154. void NAvisibleDItem(dialog, item, show)
  155.     DialogPtr    dialog;
  156.     short        item;
  157.     Boolean        show;
  158. #endif
  159. {
  160.     if (show)    ShowDItem(dialog, item);
  161.     else        HideDItem(dialog, item);
  162. }
  163.  
  164. /* set the text in a dialog item
  165.  */
  166. #ifdef __STDC__
  167. void NAsetIText(DialogPtr dialog, short item, PCstr *str)
  168. #else
  169. void NAsetIText(dialog, item, str)
  170.     DialogPtr    dialog;
  171.     short        item;
  172.     PCstr        *str;
  173. #endif
  174. {
  175.     Handle        texth;
  176.     
  177.     NAgetDHandle(dialog, item, &texth);
  178.     SetIText(texth, str);
  179. }
  180.  
  181. /* get the text in a dialog item
  182.  */
  183. #ifdef __STDC__
  184. void NAgetIText(DialogPtr dialog, short item, PCstr *str)
  185. #else
  186. void NAgetIText(dialog, item, str)
  187.     DialogPtr    dialog;
  188.     short        item;
  189.     PCstr        *str;
  190. #endif
  191. {
  192.     Handle        texth;
  193.     
  194.     NAgetDHandle(dialog, item, &texth);
  195.     GetIText(texth, str);
  196.     SetClen(str);
  197. }
  198.  
  199. /* set the appropriate radio buttons
  200.  */
  201. #ifdef __STDC__
  202. short NAradioSet(DialogPtr dialog, short firstitem, short lastitem, short setting)
  203. #else
  204. short NAradioSet(dialog, firstitem, lastitem, setting)
  205.     DialogPtr    dialog;
  206.     short        firstitem;
  207.     short        lastitem;
  208.     short        setting;
  209. #endif
  210. {
  211.     short    item;
  212.     ControlHandle    ctrl;
  213.     
  214.     for (item = firstitem; item <= lastitem; item++) {
  215.         NAgetDHandle(dialog, item, &ctrl);
  216.         SetCtlValue(ctrl, item == setting ? 1 : 0);
  217.     }
  218.     
  219.     return (setting - firstitem);
  220. }
  221.  
  222. /* get the itemno of the active radio button
  223.  */
  224. #ifdef __STDC__
  225. short NAradioGet(DialogPtr dialog, short firstitem, short lastitem)
  226. #else
  227. short NAradioGet(dialog, firstitem, lastitem)
  228.     DialogPtr    dialog;
  229.     short        firstitem;
  230.     short        lastitem;
  231. #endif
  232. {
  233.     short    item;
  234.     ControlHandle    ctrl;
  235.     
  236.     for (item = firstitem; item <= lastitem; item++) {
  237.         NAgetDHandle(dialog, item, &ctrl);
  238.         if (GetCtlValue(ctrl)) return (item);
  239.     }
  240.     
  241.     return (firstitem);
  242. }
  243.  
  244. /* an alert window with built-in param text calls
  245.  */
  246. #ifdef __STDC__
  247. short NAalertParam(short alert, short strlist, short str1, short str2, short str3, short str4)
  248. #else
  249. short NAalertParam(alert, strlist, str1, str2, str3, str4)
  250.     short    alert, strlist, str1, str2, str3, str4;
  251. #endif
  252. {
  253.     PCstr    *param1 = NULL, *param2 = NULL, *param3 = NULL, *param4 = NULL;
  254.     PCstr    store1[257], store2[257], store3[257], store4[257];
  255.     
  256.     if (str1) GetIndString(param1 = store1, strlist, str1);
  257.     if (str2) GetIndString(param2 = store2, strlist, str2);
  258.     if (str3) GetIndString(param3 = store3, strlist, str3);
  259.     if (str4) GetIndString(param4 = store4, strlist, str4);
  260.     ParamText(param1, param2, param3, param4);
  261.  
  262.     return (NAalert(alert));
  263. }
  264.